<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserRegistRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username'=>'required|regex:/.{6,18}/',
            'password'=>'required|regex:/\w{6,18}/',
            'phone'=>'required|regex:/^1[3,8]\d{9}$/',
            'email'=>'required|email'
        ];
    }


    /**
     * 获取已定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
        'username.required'=>'用户名不能为空',
        'password.required'=>'密码不能为空',
        'email.required'=>'邮箱不能为空',
        'phone.required'=>'手机号不能为空',
        'username.regex'=>'用户名需要6-18位字母数字下划线',
        'password.regex'  => '密码需要6-18位字母数字下划线组成',
        'email.email'  => '邮箱格式不正确',
        'phone.regex'=>'手机格式不正确'
        ];


    }
}
